package serviceset2

import grails.async.web.AsyncController
import org.springframework.beans.factory.annotation.Autowired
import serviceset2.feign.ServiceSet3

class SampleApi2Controller implements AsyncController {
    static responseFormats = ['json', 'xml']

    @Autowired
    ServiceSet3 serviceSet3

    def serviceSet3Proxy

    def index(String dependency) {
        def ctx = startAsync()

        ctx.start {
            def result = [provider: "sampleApi2@serviceSet2", dependency: dependency]

            switch (dependency) {
                case "restTemplate":
                    result.consumption = serviceSet3Proxy?.sampleApi3(dependency)
                    break
                case "feign":
                    result.consumption = serviceSet3?.sampleApi3(dependency)
                    break
                default:
                    result.consumption = serviceSet3Proxy?.sampleApi3(dependency)
                    break
            }

            respond result, formats: responseFormats
            ctx.dispatch()
        }
    }
}
